<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>重置密码</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.">
<link rel="stylesheet" href="resources/css/weui.min.css">
<link rel="stylesheet" href="resources/css/jquery-weui.css">
<link rel="stylesheet" href="resources/css/style.css">
</head>
<body ontouchstart>
<!--主体-->
<header class="wy-header">
  <div class="wy-header-icon-back"><span></span></div>
  <div class="wy-header-title">重置密码</div>
</header>
<div class="weui-content">
  <div class="weui-cells weui-cells_form wy-address-edit">
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">用户名</label></div>
      <div class="weui-cell__bd"><input class="weui-input" name="userName" placeholder="请输入您的用户名或邮箱"></div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">设置密码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" name="passWord" placeholder="请设置密码" type="password"></div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">确认密码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" name="confirmPassWord" placeholder="请再次输入密码" type="password"></div>
    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd">
            <label class="weui-label wy-lab">验证码</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" placeholder="请输入您的邮箱收到的验证码"  name="verifyCode" type="number">
        </div>
        <div class="weui-cell__ft">
            <button class="weui-vcode-btn" onclick="settime(this)">获取验证码</button>
        </div>
    </div>
  </div>
  <div class="weui-btn-area"><a href="javascript:submit();" class="weui-btn weui-btn_primary">确认修改</a></div>
</div>


<script src="resources/js/jquery.min.js"></script>
<script src="resources/js/fastclick.js"></script> 
<script src="resources/js/jquery-weui.min.js"></script>
<script src="resources/js/jquery.Spinner.js"></script>  
<script>

// 发送验证码
var countdown=60;
var flag = true;
function settime(obj) {
	if(flag){
		flag = false;
		var userName = $("input[name='userName']").val();
		if(userName == ''){
			$.alert("请输入您的用户名或邮箱");
	        flag = true;
	        return;
		}
		else{
			var explainCode = 1;
			$.post('autoUserValidate',{userName,explainCode},(result)=>{
		        	if(result.errorCode==0){$.toast(result.errorMsg);}
		        	else{$.toast(result.errorMsg, "cancel");}
		    }).error(()=>{$.toast("发送验证码失败", "cancel");});
		}
	}
    var code = $(obj);
    if (countdown == 0) {
        code.removeAttr('disabled');
        code.text("获取验证码");
        countdown = 60;
        flag = true;
        return;
    } else {
        code.text("重新发送(" + countdown + ")");
        code.attr('disabled',true);
        countdown--;
    }
    setTimeout(function() {
        settime(obj) }, 1000);
}


//提交数据
function submit(){
	var userName = $("input[name='userName']").val();
	var passWord = $("input[name='passWord']").val();
	var confirmPassWord = $("input[name='confirmPassWord']").val();
	var verifyCode = $("input[name='verifyCode']").val();
	if(userName == ''){$.alert("请输入您的用户名或邮箱");}
	else if(passWord == ''){$.alert("请输入您的密码");}
	else if(confirmPassWord == ''){$.alert("请输入您的确认密码");}
	else if(passWord != confirmPassWord){$.alert("两次输入的密码不一致");}
	else if(verifyCode == ''){$.alert("请输入您的验证码");}
	else{
		$.post('updatePassword',{userName,passWord,verifyCode},(result)=>{
     	if(result.errorCode==0){$.toast(result.errorMsg,()=>{location.href='userLogin'});}
     	else{$.toast(result.errorMsg, "cancel");}
     }).error(()=>{$.toast("重置密码失败", "cancel");});
	}
}

// 回退
$(".wy-header-icon-back").click(()=>{window.history.go(-1);})
// fastclick
$(function() {
    FastClick.attach(document.body);
});
</script>
</body>
</html>
